package com.weblog.weblogapi.controller;

import com.weblog.weblogapi.dao.pojo.Article;
import com.weblog.weblogapi.service.ArticleService;
import com.weblog.weblogapi.vo.ArticleVo;
import com.weblog.weblogapi.vo.Result;
import com.weblog.weblogapi.vo.params.PageParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("article")
public class ArticleController {
    @Autowired
    private ArticleService articleService;
    //首页文章列表
    //按标签和分类分类文章
    //分页
    //按标题和文章内容模糊查询
    @PostMapping
    public Result listArticle(@RequestBody PageParams pageParams){return articleService.listArticle(pageParams);}
    //十大热门文章
    @GetMapping("hotArticle")
    public Result hotArticle(){
        int limit = 5;
        return articleService.hotArticle(limit);
    }
    //十大最新文章
    @GetMapping("newArticle")
    public Result newArticle(){
        int limit =5;
        return articleService.newArticle(limit);
    }
    //查询文章详情
    @PostMapping("{id}")
    public Result findArticleById(@PathVariable("id") int id){return articleService.findArticleById(id);}
    //写文章
    @PostMapping("publish")
    public Result publishArticle(@RequestBody ArticleVo articleVo){return articleService.publish(articleVo);}
    //删除文章
    @PostMapping("delete/{id}")
    public Result deleteArticle(@PathVariable("id") int id){return articleService.deleteArticle(id);}
    //修改文章
    @PostMapping("update")
    public Result updateArticle(@RequestBody ArticleVo articleVo){return  articleService.updateArticle(articleVo);}
    //查看个人文章
    @PostMapping("findUserArticle")
    public Result findUserArticle(@RequestParam String id){return articleService.findUserArticle(id);}
}
